package com.lt.bcra.controller.questionnaire;


import com.lt.bcra.entity.BcraHealthInformation;
import com.lt.bcra.exception.BaseException;
import com.lt.bcra.service.BcraHealthInformationService;
import com.lt.bcra.result.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 个人健康信息表 前端控制器
 * </p>
 *
 * @author LuoTian
 * @since 2022-05-25
 */
@Api(tags = "4.个人健康信息表")
@CrossOrigin //跨域可以前端配置
@RestController
@RequestMapping("bcra/healthInformation")
public class BcraHealthInformationController {
    private static Logger log = LoggerFactory.getLogger(BcraHealthInformationController.class);

    @Autowired
    private BcraHealthInformationService bcraHealthInformationService;


    @PostMapping("/creatHealthInformation")
    @ApiOperation("填写个人健康信息")
    @ApiParam(value = "bcraHealthInformation")
    public ResultData creatNew(@RequestBody BcraHealthInformation bcraHealthInformation) throws BaseException {
        if (log.isDebugEnabled()) log.debug("创建个人健康信息表 BcraHealthInformationController");

        return bcraHealthInformationService.saveModule(bcraHealthInformation);
    }

    @PostMapping("/updateHealthInformation")
    @ApiOperation("修改个人健康信息")
    @ApiParam(value = "bcraHealthInformation")
    public ResultData update(@RequestBody BcraHealthInformation bcraHealthInformation) throws BaseException {
        if (log.isDebugEnabled()) log.debug("修改个人健康信息表 BcraHealthInformationController");

        return bcraHealthInformationService.updateModule(bcraHealthInformation);
    }

    @DeleteMapping("/deleteHealthInformation")
    @ApiOperation("删除个人健康信息")
    @ApiParam(value = "问卷编号")
    public ResultData delete(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除个人健康信息 BcraHealthInformationController");

        return bcraHealthInformationService.removeByQuesCode(questionnaireCode);
    }
    @GetMapping("/getHealthInformation")
    @ApiOperation("查看个人健康信息")
    @ApiParam(value = "问卷编号")
    public ResultData list(String questionnaireCode) throws BaseException{
        if (log.isDebugEnabled()) log.debug("删除个人健康信息表 BcraHealthInformationController");

        return bcraHealthInformationService.selectByQuesCode(questionnaireCode);
    }
}

